var c = 0, d = 0;
var ctime, dtime;
var xhr = null;
var vid;
var mode; //mode tracking, single/allall
var reqProcess = null;

updateIconNode = function(id, state) {
    var node = $("#tree2").dynatree("getTree").getNodeByKey(id);
    if (node != null)
    {
        if (state == 0) {
            $(node.span).addClass('dynatree-vh-stop');
        } else if (state > 0) {
            $(node.span).addClass('dynatree-vh-run');
        }
    }
}
show_vh_detil = function() {
    if (xhr != null) {
        xhr.abort();
    }
    xhr = $.ajax({
        url: 'required_php/ajx_data_vehicle_detail.php',
        success: function(data) {
            $("#vh_detil").html(data);
        }
    });
}
showPanel = function() {

    if ($('#d_panel:visible').length > 0) {
        $("#visible_panel").html("Show Info GPS");
        $("#d_panel").hide();
    } else {
        $("#visible_panel").html("Hide Info GPS");
        $("#d_panel").show();
        show_vh_detil();
    }
}
refreshTree = function() {
    $("#tree2").dynatree("getRoot").visit(function(node) {
        node.select(false);
    });
    var tree = $("#tree2").dynatree("getTree");
    tree.reload();

}
parse_json = function() {
    $.getJSON("php_script/treeview_json.php", function(data) {
        $.each(data, function() {
            $.each(this, function(k, v) {
               console.log(v.id_group);
            });
        });
    });
}

vhSelectUser = function(uid, vhperpage, vhpage) {

    $.get('required_php/ajx_data_vehicle.php?uid=' + uid + '&vhperpage=' + vhperpage + '&vhpage=' + vhpage, function(data) {
        $("#vh").html(data);
    });
    document.fvlist.vcekall.checked = false;
    cekUncek();
    bounded = false;
}
parseDate = function(d)
{
    var p = d.split(' ');
    var q = p[0].split('-');
    var r = p[1].split(':');
    return new Date(q[0], q[1] - 1, q[2], r[0], r[1], r[2]);
}
countDays = function(d1, d2)
{
    var a_day = 1000 * 60 * 60 * 24;
    var d1_date = parseDate(d1);
    var d2_date = parseDate(d2);
    var d1_ms = d1_date.getTime();
    var d2_ms = d2_date.getTime();

    var diff_ms = d2_ms - d1_ms;

    return Math.round(diff_ms / a_day);
}


dMonth = function(m)
{
    var b;
    switch (String(m)) {
        case '01':
            b = 'Januari';
            break;
        case '02':
            b = 'Pebruari';
            break;
        case '03':
            b = 'Maret';
            break;
        case '04':
            b = 'April';
            break;
        case '05':
            b = 'Mei';
            break;
        case '06':
            b = 'Juni';
            break;
        case '07':
            b = 'Juli';
            break;
        case '08':
            b = 'Agustus';
            break;
        case '09':
            b = 'Spetember';
            break;
        case '10':
            b = 'Oktober';
            break;
        case '11':
            b = 'Nopember';
            break;
        case '12':
            b = 'Desember';
            break;
        default:
            break;
    }
    return b;
}
indDate = function(d)
{
    var fr = d.split(' ');
    var er = fr[0].split('-');
    var id = er[2] + " " + dMonth(er[1]) + " " + er[0] + " " + fr[1];
    return id;
}
direction = function(a)
{
    var d;
    if ((a > 337.5 || a <= 22.5) || a == 0)
        d = 'Utara';
    if (a > 22.5 && a <= 67.5)
        d = 'Timur laut';
    if (a > 67.5 && a <= 112.5)
        d = 'Timur';
    if (a > 112.5 && a <= 157.5)
        d = 'Tenggara';
    if (a > 157.5 && a <= 202.5)
        d = 'Selatan';
    if (a > 202.5 && a <= 247.5)
        d = 'Barat daya';
    if (a > 247.5 && a <= 292.5)
        d = 'Barat';
    if (a > 292.5 && a <= 337.5)
        d = 'Barat laut';
    return d;
}